import { createDom, createTitle } from '../utils'
import { checkFileSize, checkFileType, checkMobile, checkEmail, checkIdCard } from '../../lib/index'

// 标题
createTitle('校验')

// 判断文件类型
;(function () {
  const input = createDom('input', [''], { accept: 'image/*', type: 'file' }, false)
  const p = createDom('p', ['判断文件类型'], {}, false)
  createDom('div', [p, input], { class: 'item' })
  input.addEventListener('change', (e: any) => {
    const f = e.target.files[0]
    const status = checkFileType(f.name, ['.svg'])
    console.log(status, 'checkFileType')
    e.target.value = ''
  })
})()

// 判断文件大小
;(function () {
  const input = createDom('input', [''], { accept: '*', type: 'file' }, false)
  const p = createDom('p', ['判断文件大小'], {}, false)
  createDom('div', [p, input], { class: 'item' })
  input.addEventListener('change', (e: any) => {
    const f = e.target.files[0]
    console.log(f, 'f')
    const status = checkFileSize(f.size, 1)
    console.log(status, 'checkFileSize')
    e.target.value = ''
  })
})()

// 判断手机号码
;(function () {
  const input: any = createDom('input', [''], { type: 'text' }, false)
  const p = createDom('p', ['判断手机号码'], {}, false)
  const button = createDom('button', ['验证'], {}, false)
  createDom('div', [p, input, button], { class: 'item' })
  button.addEventListener('click', () => {
    const status = checkMobile(input.value)
    console.log(status, 'checkMobile')
  })
})()

// 判断邮箱格式
;(function () {
  const input: any = createDom('input', [''], { type: 'text' }, false)
  const p = createDom('p', ['判断邮箱格式'], {}, false)
  const button = createDom('button', ['验证'], {}, false)
  createDom('div', [p, input, button], { class: 'item' })
  button.addEventListener('click', () => {
    const status = checkEmail(input.value)
    console.log(status, 'checkEmail')
  })
})()

// 判断身份证号码格式
;(function () {
  const input: any = createDom('input', [''], { type: 'text' }, false)
  const p = createDom('p', ['判断身份证号码格式'], {}, false)
  const button = createDom('button', ['验证'], {}, false)
  createDom('div', [p, input, button], { class: 'item' })
  button.addEventListener('click', () => {
    const status = checkIdCard(input.value)
    console.log(status, 'checkIdCard')
  })
})()
